package com.booby.design.factory.simple;

import com.booby.design.factory.Cpu;
import com.booby.design.factory.I3Cpu;
import com.booby.design.factory.I5Cpu;
import com.booby.design.factory.I7Cpu;
import org.apache.commons.lang3.StringUtils;

/**
 * 功能描述: 简单工厂
 *
 * @author: lizt
 * @date: 2019-06-30 14:30
 **/

public class SimpleFactory {

    public Cpu getCpu(String key){
        key = StringUtils.trimToNull(key);
        if (null == key){
            return null;
        }
        if (key.equals("I3")){
            return new I3Cpu();
        }
        if (key.equals("I5")){
            return new I5Cpu();
        }
        if (key.equals("I7")){
            return new I7Cpu();
        }
        return null;
    }

    public static void main(String[] args) {
        SimpleFactory simpleFactory = new SimpleFactory();
        I3Cpu i3Cpu = (I3Cpu) simpleFactory.getCpu("I3");
        i3Cpu.run();

        I5Cpu i5Cpu = (I5Cpu) simpleFactory.getCpu("I5");
        i5Cpu.run();

    }
}
